﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ciripescu_WebRole.BL;
using Ciripescu_WebRole.Entities;

namespace Ciripescu_WebRole.Master
{
    public partial class continut : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                UserManager uManag = new UserManager();
                User usr = uManag.GetItem((string)Session["UserName"]);
                imgProfile.ImageUrl = usr.PictureUri;

                UrmarireManager urmManag = new UrmarireManager();
                //gvUrmarindPe.DataSource  = urmManag.FollowingTopN(usr.PartitionKey,36);
                //gvUrmarindPe.DataBind();
                ListView1.DataSource = urmManag.GetFollowingTopN(usr.PartitionKey, 30);
                ListView1.DataBind();
            }
            
        }

        public string GetCurrentUser()
        {
            return (string)Session["UserName"];
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            //Session.Add("UserName", "pitagora");

            if (Session["UserName"] == null)
                Response.Redirect("/");
        }

        public string GetNrUrmariti()
        {
            UserManager uManag = new UserManager();
            User usr = uManag.GetItem((string)Session["UserName"]);
            return usr.NrUrmariti.ToString();
        }

        public string GetNrUrmaritori()
        {
            UserManager uManag = new UserManager();
            User usr = uManag.GetItem((string)Session["UserName"]);
            return usr.NrUrmaritori.ToString();
        }

        public string GetNrCirips()
        {
            CiripManager cManag = new CiripManager();
            return cManag.GetNrOfCirips((string)Session["UserName"]).ToString();
        }


        protected string GetCurrentPage()
        {
            string url = Request.RawUrl;
            if (url.StartsWith("/home"))
                return "home";
            else if (url.StartsWith("/replies"))
                return "replici";
            else if (url.StartsWith("/all"))
                return "toate";
            else if (url.StartsWith("/directmessages"))
                return "direct";
            else if (url.StartsWith("/reply")) // este defapt /home deghizat :P
                return "home";

            return "";
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton btn = (ImageButton)sender;
            string arg = btn.CommandArgument;
            Response.Redirect("\\u\\" + arg);
        }
    }
}
